LBB

扫描和修改 Git History

# 扫描和修改 Git History 有时候我们需要将一些内部的项目库开源,我们希望保留 git 的历史提交记录,但面临一些问题。主要有两点,我们希望 commit author 能和 GitHub 上的用户对应上,以及担心 git history 中可能存在一些 secret 信息。 ## 扫描 通过 `git log --format='%ae'` 获取到所有 commit 信息中的 author email。 使用 https://github.com/awslabs/git-secrets 扫描 history 中可能存在的 secret 信息。 ## 修改 history Git 官方文档中有关于如何重写 history 的教程,https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History。 下面是修改 commit author 信息的例子: ```bash $ git filter-branch --commit-filter ' if [ "$$GIT_AUTHOR_EMAIL" = "schacon@localhost" ]; then GIT_AUTHOR_NAME="Scott Chacon"; GIT_AUTHOR_EMAIL="schacon@example.com"; git commit-tree " $@"; else git commit-tree "$ @"; fi' HEAD ```
扫描和修改 Git History | LBB